package com.example.danangtravel.ATM;

import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

import com.exam.danangtranel.filed.ATM;
import com.example.danangtravel.DataAccess;
import com.example.danangtravel.R;
import com.example.danangtravel.checknetwork;
import com.example.danangtravel.R.layout;
import com.example.danangtravel.R.menu;
import com.example.danangtravel.map.RoutePath;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ImageButton;
import android.widget.Toast;

public class ATM_Activity extends Activity {
	public DataAccess dataaccess;
	private ExpandableListView mExpandableList;
	public ArrayList<String> listTitle;
	public List<ATM> listatm;
	public ImageButton btnhome;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.atm_activity);
		btnhome = (ImageButton) findViewById(R.id.btn_hatm);
		btnhome.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		mExpandableList = (ExpandableListView) findViewById(R.id.expandable_list);
		ArrayList<ATM_Titlee> arrayTitle = new ArrayList<ATM_Titlee>();
		ArrayList<ATM> arrayAdress;
		try {
			dataaccess = new DataAccess(this);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		dataaccess.open();
		listatm = new ArrayList<ATM>();
		listTitle = new ArrayList<String>();
		listTitle = dataaccess.getATM();
		for (int i = 0; i < listTitle.size(); i++) {

			ATM_Titlee atm = new ATM_Titlee();
			atm.setTitle(listTitle.get(i));
			listatm = dataaccess.getChildATM(listTitle.get(i));
			arrayAdress = new ArrayList<ATM>();
			for (int j = 0; j < listatm.size(); j++) {

				arrayAdress.add(listatm.get(j));
			}
			atm.setChild(arrayAdress);
			arrayTitle.add(atm);
		}
		dataaccess.close();
		mExpandableList.setAdapter(new ATM_Adapter(ATM_Activity.this,
				arrayTitle));
	}

}
